Output Device

Output Device #

Intro #

In this page, I will document the process of using an 1.5inch OLED Module from Waveshare to the board.


Basic info #

1.5inch OLED module from Waveshare
  • Controller: SSD1327
  • Support interface: 4-wire SPI/I2C
  • Resolution: 128 x 128
  • Display size: 1.5inch
  • Dimensions: 44.5mm * 37mm
  • Display color: 16-bit grayscale
  • Working voltage: 3.3V/5V
Back side of the module
PIN USAGE
VCC Power input
GND Ground
DIN Date input
SCL Clock input
CS Chip select
DC Data/command signal selection
RST Reset signal

Connections #

This board can support both I2C and SPI.

Use 4-wire SPI: (factory setting)

  • BS is connected to 0 and connected to GND
  • DIN is connected to the control pin MOSI
  • CLK is connected to the control pin SCK

Using I2C:

  • BS is connected to 1 and connected to VCC
  • DIN is connected to control pin SDA
  • CLK is connected to control pin SCL
  • CS can be left unconnected, but don’t leave DC floating

Default connection settings are for the SPI connection.

Connections based on the XIAO board pins.

Pins layout for Xiao board

Pins used:

xiao board PIN oled board pin
D0 Button / RESET
D2 CS / Chip Select
D3 DC / Data/command signal selection
D8 – SCK CLK
D10 – MOSI DIN

Board design #

I designed the board based on the required connections.

Schematic for OLED board
PCB design
Board IRL

There’s nothing special to say about it other than avoid putting rivets to your board which brings a lot of potential connectivity troubles. At first I found some rivets have unstable contact with the pads, fixed with soldering rivets to the pads (kind of) as you can see in the picture. So far it was doing fine, but I believe there are more optimal approaches to improve that.

Programming #

Libraries #

Two libraries are tested for this module. Initially, I attempted to use the original library from Waveshare.

Waveshare tutorial

Unfortunately it failed to compile due to font-related issues. Probably have something to do with the involve of chinese characters.

Then I switched to the Adafruit library for the SSD 1327. Which worked with lots of presets and functions that are easy to use. Here’s the link for that library:

Result from the sample program. Really fancy visual effects for such a small screen.

Gyro visualization #

After trying out the functions for the display, I decided to make a simple visualization for the Gyroscope that I used in the Input device week.

The goal is to visualize the three axes (pitch, roll, yaw) data. I used a simple cursor which contains a circle and a triangle to indicate that. The pitch and roll dimensions are depicted as the X and Y coordinates of the cursor on the screen, while the dimension of yaw was presented by the rotation of the cursor.

To draw the cursor, firstly I calculated the center coordinate by mapping the pitch and roll angle to the screen size, and then draw the circle around that:

// Calculate coordinate
x = map(long(ax),90,-90,0,display.width());
y = map(long(ay),-90,90,0,display.height());

// Draw circle
display.drawCircle(x, y, radius, SSD1327_WHITE);

After that, I calculate the three points for drawing the triangle:

// Draw triangle
rad1 = az / 180 * M_PI;
rad2 = (az+120) / 180 * M_PI;
rad3 = (az+240) / 180 * M_PI;
display.drawTriangle(int(x + sin(rad1)*t_size), int(y + cos(rad1)*t_size),  
                int(x + sin(rad2)*t_size), int(y + cos(rad2)*t_size),  
                int(x + sin(rad3)*t_size), int(y + cos(rad3)*t_size), SSD1327_WHITE);
display.display();

Here is the final result I have achieved.

The visualization is straightforward and provides accurate representation of the data. I do wish that there are more functions for draw so that I can display 3D or fake 3D effects on the screen. I will look into that in the Interface and Application week.